package DEEPERsource.DEEPERsource.source.preprocessing;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import deeper.Protein;

/**
 * Implements minimal requirements for preprocessor, i.e. substitutes protein names with unique id's
 * Does not take into account the fact, that protein name could be distributed in the sentence, i.e.
 * assumes that startOffset[] and endOffset[] have one element each.
 * @author tfayruzo
 *
 */
public class SimplePreprocessor implements Preprocessor {

	public Map<String, String> preprocessSentence(String sentence, Set<Protein> interactors, List<Protein> proteins) {
		Map<String, String> result = new TreeMap<String, String>();
		//substituting all protein names with unique ID's
		int offset = 0;
		int c = 0; //term index
		Collections.sort(proteins);
		for(Protein p : proteins){
			String id = "ccoterm"+c;
			int length = p.endOffset[0] - p.startOffset[0] + 1;
			p.startOffset_mod = p.startOffset[0] + offset;
			p.endOffset_mod = p.endOffset[p.endOffset.length-1] + offset;
			p.name_mod = id;
			sentence = sentence.substring(0,p.startOffset_mod) + id + sentence.substring(p.endOffset_mod+1);
			offset += id.length() - length;
			result.put(id, p.name);
			c++;
		}
		result.put("sentence", sentence);
		return result;
	}

}
